package asSkinStyle.draw
{
	import flash.display.GradientType;
	import flash.events.Event;
	import flash.geom.Matrix;
	
	/**
	 * 画圆组件
	 * @author Pelephone
	 * @website http://cnblogs.com/pelephone
	 */
	public class CircleSprite extends SpriteDraw
	{
		/**
		 * 构造画圆组件
		 */
		public function CircleSprite(uiName:String="draw")
		{
			super(uiName);
		}
		
		override protected function draw():void
		{
			if(this.bgAlpha){
				if(this.bgColor>=0 && this.bgColor2<0)
				{
					graphics.clear();
					graphics.beginFill(this.bgColor,this.bgAlpha);
				}
				else if(this.bgColor>=0 && this.bgColor2>=0) {
					var matr:Matrix = new Matrix();
					matr.createGradientBox(this.width, this.height, this.bgRotaion);
					graphics.beginGradientFill(GradientType.LINEAR,[this.bgColor,this.bgColor2],
						[this.bgAlpha,this.bgAlpha],[0x00, 0xFF],matr);
				}
				
				var linAlpha:Number = (borderColor>0)?1:0;
				graphics.lineStyle(this.border,this.borderColor,linAlpha);
				
				if(width==height)
					graphics.drawCircle(width/2,height/2,width/2);
				else
					graphics.drawEllipse(width/2,height/2,width,height);
				
				if(this.bgColor>=0) graphics.endFill();
			}
			super.draw();
		}
		
		/**
		 * 设置圆半径
		 */
		public function set radius(value:Number):void
		{
			width = height = value;
		}
		
		public function get radius():Number
		{
			if(width==height)
				return width;
			else
				return NaN;
		}
	}
}